<template>
  <div>
    <el-container>
      <el-header>
        <div class="box">
          <div class="log">
            <img src="../assets/logo.png" alt="" />
            <span>电商后台管理系统</span>
          </div>
          <div class="btn">
            <el-button type="info" @click="exit">退出</el-button>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="flag ? '80px' : '200px'">
          <div
            style="
              text-align: center;
              background-color: #4a5064;
              color: white;
              cursor: pointer;
            "
          >
            <span @click="fold">|||</span>
          </div>
          <el-menu
            router
            unique-opened
            :default-active="activePath"
            active-text-color="#409EFF"
            :collapse="flag"
            :collapse-transition="false"
            background-color="#333744"
          >
            <el-submenu
              :index="'' + item.id"
              v-for="item in leftList"
              :key="item.id"
            >
              <template slot="title"
                ><i :class="oneLog[item.id]"></i>
                <span> {{ item.authName }}</span>
              </template>

              <el-menu-item
                :index="'/' + value.path"
                v-for="value in item.children"
                :key="value.id"
              >
                <i :class="twoLog[value.id]"></i>
                <span> {{ value.authName }}</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "MyVueHome",

  data() {
    return {
      // 左侧菜单的数据
      leftList: [],
      //   一级图标
      oneLog: {
        125: "iconfont icon-yidongduanicon-",
        103: "iconfont icon-permissions",
        101: "iconfont icon-shangpingouwudai2",
        102: "iconfont icon-dingdan",
        145: "iconfont icon-shuju",
      },
      //   二级图标
      twoLog: {
        110: "iconfont iconfont icon-yidongduanicon-",
        111: "iconfont icon-jiaosepeizhi",
        112: "iconfont icon-quanxianguankong",
        104: "iconfont icon-shangpingouwudai2",
        115: "iconfont icon-tx-liujiaoxingxing",
        121: "iconfont icon-quanbufenlei",
        107: "iconfont icon-fl-dingdan",
        146: "iconfont icon-qizi",
      },

      // 折叠菜单
      flag: false,
    };
  },

  mounted() {},
  created() {
    this.$http.get("menus").then((res) => {
      this.leftList = res.data.data;
      console.log(this.leftList);
    });
  },
  methods: {
    // 退出
    exit() {
      sessionStorage.removeItem("token");

      this.$router.push("/");
    },

    // 折叠
    fold() {
      this.flag = !this.flag;
    },
  },
  computed: {
    activePath() {
      return this.$route.meta.parentPath
        ? this.$route.meta.parentPath
        : this.$route.path;
    },
  },
};
</script>

<style lang="scss" scoped>
.el-header {
  padding: 0;
  .box {
    background-color: #373f41;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .log {
      width: 180px;
      color: white;
      display: flex;
      align-items: center;
      justify-content: space-between;
      img {
        width: 40px;
      }
    }
    .btn {
      width: 100px;
    }
  }
}
.el-container {
  height: 100vh;

  .el-aside {
    background-color: #333744;

    :deep .el-submenu__title {
      background-color: #333744;
      width: 200px;
      color: white;
    }
    .el-menu-item {
      background-color: #333744;

      color: white;
    }
  }
}
</style>